
#include <BFont>
#include <BStyle>
#include <BWidget>
#include <BMenuBar>

#include "member_BMenuBar.h"
#include "member_BMenu.h"

using namespace BWE;

member_BMenuBar::member_BMenuBar(BMenuBar* menuBar)
{
	boss = menuBar;
	spacing = 3;
	align = Align_Center;
	hoverIndex = -1;
	pressed = false;
	dirty = false;
}
member_BMenuBar::~member_BMenuBar()
{

}

void member_BMenuBar::adjustMenuRects()
{
	const BFont* font = boss->font();
	if (!font)
		return;

	BRect clientRect = boss->clientRect();
	int ch = clientRect.height();
	int cw = clientRect.width();

	int posX = clientRect.left() + spacing;
	int posY = clientRect.top();
	for (int i = 0; i < items.size(); i++)
	{
		const BMenu* menu = items[i].menu;
		BSize textSize;
		const BString& t_title = menu_member(menu)->t_title;
		if (t_title.size())
			textSize = font->textSize(t_title);
		else
			textSize = font->textSize(menu->title());
		BRect rect(posX, posY, textSize.width() + spacing + spacing, ch);
		items[i].rect = rect.align(align, textSize);
		posX += textSize.width() + spacing;
	}
	contentSize.set(posX, font->height());
}
